package com.ruoyi.project.tickets.controller;

import java.util.Date;
import java.util.List;

import com.ruoyi.project.tickets.domain.vo.OutStockDetailsVo;
import com.ruoyi.project.tickets.domain.vo.OutStockVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tickets.domain.OutStockDetails;
import com.ruoyi.project.tickets.service.IOutStockDetailsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 出库详情Controller
 * 
 * @author 孙山伟
 * @date 2023-07-01
 */
@RestController
@RequestMapping("/tickets/details")
public class OutStockDetailsController extends BaseController
{
    @Autowired
    private IOutStockDetailsService outStockDetailsService;

    /**
     * 查询出库详情列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:details:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutStockDetails outStockDetails)
    {
        startPage();
        List<OutStockDetails> list = outStockDetailsService.selectOutStockDetailsList(outStockDetails);
        return getDataTable(list);
    }

    /**
     * 导出出库详情列表
     */
    @PreAuthorize("@ss.hasPermi('tickets:details:export')")
    @Log(title = "出库详情", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OutStockDetails outStockDetails)
    {
        List<OutStockDetails> list = outStockDetailsService.selectOutStockDetailsList(outStockDetails);
        ExcelUtil<OutStockDetails> util = new ExcelUtil<OutStockDetails>(OutStockDetails.class);
        return util.exportExcel(list, "details");
    }

    /**
     * 获取出库详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('tickets:details:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(outStockDetailsService.selectOutStockDetailsById(id));
    }

    @GetMapping("/listByStockId/{stockId}")
    public AjaxResult listByStockId(@PathVariable Long  stockId)
    {

        List<OutStockDetailsVo> list = outStockDetailsService.listByStockId(stockId);
        return AjaxResult.success(list);
    }
    /**
     * 新增出库详情
     */
    @PreAuthorize("@ss.hasPermi('tickets:details:add')")
    @Log(title = "出库详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutStockDetails outStockDetails)
    {
        return toAjax(outStockDetailsService.insertOutStockDetails(outStockDetails));
    }

    /**
     * 修改出库详情
     */
    @PreAuthorize("@ss.hasPermi('tickets:details:edit')")
    @Log(title = "出库详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OutStockDetails outStockDetails)
    {
        return toAjax(outStockDetailsService.updateOutStockDetails(outStockDetails));
    }

    /**
     * 删除出库详情
     */
    @PreAuthorize("@ss.hasPermi('tickets:details:remove')")
    @Log(title = "出库详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{updateTimes}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(outStockDetailsService.deleteOutStockDetailsByIds(ids));
    }
}
